package yuque.a1至20.CalculateEContinuously;

/**
 * ClassName: CalculateEContinuously
 * Package: yuque
 * Description:
 *
 * @Author fjorid
 * @Create 2024/12/30 19:20
 * @Version 1.0
 */
/*public class CalculateEContinuously {
    public static void main(String[] args) {
        double e = 1.0; // e的初始值
       /double previousE = 0.0; // 上一次计算的e值
        double term = 1.0; // 当前项的值
        int n = 1; // 项数，从1开始

        // 定义精度阈值
        double precision = 1e-15;

        while (true) {
            term = 1.0 / factorial(n); // 计算当前项
            e += term; // 累加到e的值中

            // 检查是否达到了所需的精度
            if (Math.abs(e - previousE) < precision) {
                break; // 如果达到了精度，退出循环
            }

            previousE = e; // 更新e的值，用于下一次迭代的比较
            n++; // 增加项数
        }

        System.out.println("The approximate value of e is: " + e);
    }

    // 计算阶乘的辅助方法
    private static double factorial(int n) {
        double result = 1.0;
        for (int i = 1; i <= n; i++) {
            result *= i;
        }
        return result;
    }
}
*/
